<template>
  <view class="example-page">
    <!-- 头部标题区域 -->
    <view class="header-section">
      <view class="title-container">
        <view class="title-icon">🏥</view>
        <view class="title text-[40rpx] font-bold text-white">医院选择器示例</view>
        <view class="subtitle text-[24rpx] text-blue-100 mt-[8rpx]">Hospital Selector Demo</view>
      </view>
    </view>

    <!-- 主要内容区域 -->
    <view class="content-section">
      <!-- 使用示例 -->
      <view class="example-section">
        <view class="section-header">
          <view class="section-icon">📋</view>
          <view class="section-title text-[32rpx] font-semibold text-gray-800">基础使用</view>
        </view>
        <view class="selector-container">
          <HospitalSelector 
            v-model="selectedData"
            placeholder="请选择医院/科室/床位"
            @confirm="onConfirm"
          />
        </view>
      </view>

      <!-- 显示选中的数据 -->
      <view v-if="selectedData.hospital" class="result-section">
        <view class="section-header">
          <view class="section-icon">✅</view>
          <view class="section-title text-[32rpx] font-semibold text-gray-800">选择结果</view>
        </view>
        <view class="result-card">
          <view class="result-header">
            <view class="result-icon">🎯</view>
            <view class="result-title text-[28rpx] font-medium text-gray-700">已选择信息</view>
          </view>
          
          <view class="result-content">
            <view class="result-item">
              <view class="item-icon">🏥</view>
              <view class="item-content">
                <text class="item-label text-[24rpx] text-gray-500">医院</text>
                <text class="item-value text-[30rpx] font-medium text-gray-900">{{ selectedData.hospital?.title }}</text>
              </view>
            </view>
            
            <view class="result-item">
              <view class="item-icon">🏢</view>
              <view class="item-content">
                <text class="item-label text-[24rpx] text-gray-500">科室</text>
                <text class="item-value text-[30rpx] font-medium text-gray-900">{{ selectedData.department?.title }}</text>
              </view>
            </view>
            
            <view class="result-item">
              <view class="item-icon">🛏️</view>
              <view class="item-content">
                <text class="item-label text-[24rpx] text-gray-500">床位</text>
                <text class="item-value text-[30rpx] font-medium text-gray-900">{{ selectedData.bed?.name }}</text>
              </view>
            </view>
          </view>
        </view>
      </view>

      <!-- 空状态 -->
      <view v-else class="empty-state">
        <view class="empty-icon">📝</view>
        <view class="empty-text text-[28rpx] text-gray-500">请选择医院、科室和床位</view>
        <view class="empty-hint text-[24rpx] text-gray-400 mt-[8rpx]">选择完成后将显示详细信息</view>
      </view>

      <!-- 操作按钮 -->
      <view class="action-section">
        <view class="btn-reset" @click="resetSelection">
          <view class="btn-icon">🔄</view>
          <text class="btn-text text-[30rpx] font-medium">重置选择</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import HospitalSelector from './HospitalSelector.vue'

// 类型定义
interface Hospital {
  key: string
  title: string
  value: any
  parentId: string
  children: any
  leaf: boolean
}

interface Department {
  key: string
  leaf: boolean
  parentId: string
  title: string
}

interface Bed {
  code: string
  deptId: string
  id: string
  name: string
}

interface SelectedData {
  hospital: Hospital | null
  department: Department | null
  bed: Bed | null
}

// 选中的数据
const selectedData = ref<SelectedData>({
  hospital: null,
  department: null,
  bed: null
})

// 确认选择回调
const onConfirm = (data: SelectedData) => {
  console.log('确认选择:', data)
  // 这里可以处理选择确认后的逻辑
  // 比如保存到后端、更新其他组件状态等
}

// 重置选择
const resetSelection = () => {
  selectedData.value = {
    hospital: null,
    department: null,
    bed: null
  }
}
</script>

<style scoped>
.example-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  position: relative;
}

/* 头部区域 */
.header-section {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  padding: 60rpx 32rpx 40rpx;
  position: relative;
  overflow: hidden;
}

.header-section::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  animation: float 6s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(180deg); }
}

.title-container {
  text-align: center;
  position: relative;
  z-index: 1;
}

.title-icon {
  font-size: 60rpx;
  margin-bottom: 16rpx;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* 内容区域 */
.content-section {
  background: #f8fafc;
  border-radius: 32rpx 32rpx 0 0;
  margin-top: -20rpx;
  padding: 40rpx 32rpx;
  position: relative;
  z-index: 2;
  min-height: calc(100vh - 200rpx);
}

/* 示例区域 */
.example-section {
  background: white;
  border-radius: 20rpx;
  padding: 32rpx;
  margin-bottom: 32rpx;
  box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.08);
  border: 1rpx solid rgba(79, 70, 229, 0.1);
  position: relative;
  overflow: hidden;
}

.example-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4rpx;
  background: linear-gradient(90deg, #4f46e5, #7c3aed, #ec4899);
}

.section-header {
  display: flex;
  align-items: center;
  margin-bottom: 24rpx;
}

.section-icon {
  font-size: 32rpx;
  margin-right: 12rpx;
}

.selector-container {
  position: relative;
}

/* 结果区域 */
.result-section {
  background: white;
  border-radius: 20rpx;
  padding: 32rpx;
  margin-bottom: 32rpx;
  box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.08);
  border: 1rpx solid rgba(34, 197, 94, 0.1);
  position: relative;
  overflow: hidden;
}

.result-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4rpx;
  background: linear-gradient(90deg, #22c55e, #16a34a, #15803d);
}

.result-card {
  background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
  border-radius: 16rpx;
  padding: 24rpx;
  border: 1rpx solid rgba(34, 197, 94, 0.2);
}

.result-header {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
  padding-bottom: 16rpx;
  border-bottom: 1rpx solid rgba(34, 197, 94, 0.1);
}

.result-icon {
  font-size: 28rpx;
  margin-right: 12rpx;
}

.result-content {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
}

.result-item {
  display: flex;
  align-items: center;
  background: white;
  border-radius: 12rpx;
  padding: 20rpx;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
  border: 1rpx solid rgba(34, 197, 94, 0.1);
  transition: all 0.3s ease;
}

.result-item:hover {
  transform: translateY(-2rpx);
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
}

.item-icon {
  font-size: 32rpx;
  margin-right: 16rpx;
  width: 48rpx;
  height: 48rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(34, 197, 94, 0.1);
  border-radius: 50%;
}

.item-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.item-label {
  margin-bottom: 4rpx;
  font-weight: 500;
}

.item-value {
  font-weight: 600;
  color: #1f2937;
}

/* 空状态 */
.empty-state {
  background: white;
  border-radius: 20rpx;
  padding: 60rpx 32rpx;
  text-align: center;
  margin-bottom: 32rpx;
  box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.08);
  border: 1rpx solid rgba(156, 163, 175, 0.1);
}

.empty-icon {
  font-size: 80rpx;
  margin-bottom: 20rpx;
  opacity: 0.6;
}

.empty-text {
  font-weight: 500;
  margin-bottom: 8rpx;
}

.empty-hint {
  opacity: 0.8;
}

/* 操作按钮 */
.action-section {
  margin-top: 32rpx;
}

.btn-reset {
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  border: 1rpx solid #d1d5db;
  border-radius: 16rpx;
  padding: 24rpx 32rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12rpx;
  transition: all 0.3s ease;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
}

.btn-reset:active {
  transform: translateY(2rpx);
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
}

.btn-icon {
  font-size: 28rpx;
}

.btn-text {
  color: #6b7280;
  font-weight: 600;
}

/* 响应式调整 */
@media (max-width: 750rpx) {
  .content-section {
    padding: 32rpx 24rpx;
  }
  
  .example-section,
  .result-section {
    padding: 24rpx;
  }
  
  .result-item {
    padding: 16rpx;
  }
}
</style>
